import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//引入全局样式
import "@/assets/css/common.scss";
import 'normalize.css'

//导入骨架屏 组件
import SkeleonView from '@/components/utils/SkeleonView'
Vue.component('SkeleonView', SkeleonView)

//引入提示框
import message from '@/components/utils/Message'
Vue.prototype.message = message

//确定框组件
import confirm from '@/components/utils/Confirm'
Vue.prototype.$confirm = confirm

Vue.config.productionTip = false
//图片懒加载
import defaultImg from '@/assets/img/404.png'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

//设置全局自定义指令
Vue.directive('lazy', {
  inserted(el, binding) {
    let options = { threshold: 0 }
    let observer = new IntersectionObserver(([{ isIntersecting }]) => {
      if (isIntersecting) {
        // console.log(el);
        observer.unobserve(el)
        //图片加载失败  钩子函数onerror js自带
        el.onerror = () => {
          el.src = defaultImg
        }
        el.src = binding.value
      }
    }, options)
    observer.observe(el)
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
